<?php defined('SYSPATH') or die('No direct script access.');

class Controller_List extends Controller {

	public function action_index()
	{

		//считаем торренты для счетчика страниц (пагинатор)
		$count = ORM::factory('torrent')->count_all();
		$pagination = Pagination::factory(array(
			                'total_items'    => $count,
			                'items_per_page' => 3,
			                'current_page'   => array('source' => 'route', 'key' => 'page'),
		));

		//рендер пагинатора
		$page_links = $pagination->render();

		$torrents = ORM::factory('torrent')
		->order_by('id','desc')
		->limit($pagination->items_per_page)
		->offset($pagination->offset)
		->find_all();

		$torrentinlist = "";
		foreach ($torrents as $torrent) {
			$torrentinlist .= 	View::factory('torrents/torrent-in-list')
			->set('torrent',$torrent)
			->render();
		}

		$user = ORM::factory('user')
		->where('id', '=', Helper_User::get_logged())
		->find();

		$content = View::factory('template')
		->set('content',$torrentinlist . $page_links)
		->set('left',	View::factory('menus/usermenu')
		->set('user',$user));
		$this->response->body($content);
	}

} // End List
